package inabit.impl.data.types;

/**@author Rafael Rocha*/
public class DiscreteType extends NumericType{
	
	private long min, max;
	public DiscreteType(long min, long max) {
		this.min = min;
		this.max = max;
	}
	@Override
	public String getVarValue(String value) {
		Double d = Double.parseDouble(value);
		if(d.longValue() == d){
			return Long.toString(d.longValue());
		}
		return null;
	}

	@Override
	public boolean isAcceptableValue(String value) {
		
		try {
			Double d = Double.parseDouble(value);
			Long l = d.longValue();
			if((d - l) != 0.0){
				return false;
			}
			boolean acceptable = true;
			acceptable = acceptable && l >= min;
			acceptable = acceptable && l <= max;
			
			return acceptable;
		}catch(NumberFormatException e) {
			return false;
		}
	}
	@Override
	public String getName() {
		return "discrete";
	}
	@Override
	public String getExtendedName() {
		return "discrete (" + min + ", " + max + ")";
	}
}
